package com.me.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

public class FileUtil {
	
	public static String readFile(String absolutePath,String charset) {
		File file = new File(absolutePath);
		StringBuffer sBuffer = new StringBuffer();
		if (file.canRead()) {
			try {
				InputStream is = new FileInputStream(file);
				InputStreamReader isr = new InputStreamReader(is,charset);
				BufferedReader br = new BufferedReader(isr);
				int len;
				char[] cbuff = new char[1024*8];
				
				while((len = br.read(cbuff)) !=-1 ) {
					sBuffer.append(cbuff,0,len);
				}
				
				br.close();
				isr.close();
				is.close();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
			
		}
		return sBuffer.toString();
	}
}

